package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.domain.ZhDeptInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhGameInfo;
import com.ruoyi.system.service.IZhGameInfoService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;

/**
 * 游戏 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-05
 */
@Controller
@RequestMapping("/system/zhGameInfo")
public class ZhGameInfoController extends BaseController
{
    private String prefix = "system/zhGameInfo";

	@Autowired
	private IZhGameInfoService zhGameInfoService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:view")
	@GetMapping()
	public String zhGameInfo(ZhGameInfo zhGameInfo,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameInfo.getParams())));
		return prefix + "/zhGameInfo";
	}
	
	/**
	 * 查询游戏列表
	 */
	// @DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhGameInfo zhGameInfo)
	{
		startPage();
        List<ZhGameInfo> list = zhGameInfoService.selectZhGameInfoList(zhGameInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出游戏列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhGameInfo zhGameInfo)
    {
    	List<ZhGameInfo> list = zhGameInfoService.selectZhGameInfoList(zhGameInfo);
        ExcelUtil<ZhGameInfo> util = new ExcelUtil<ZhGameInfo>(ZhGameInfo.class);
        return util.exportExcel(list, "zhGameInfo");
    }
	
	/**
	 * 新增游戏
	 */
	@RequiresPermissions("system:zhGameInfo:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhGameInfo zhGameInfo,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameInfo.getParams())));
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:add")
	@Log(title = "游戏", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhGameInfo zhGameInfo)
	{		
		return toAjax(zhGameInfoService.insertZhGameInfo(zhGameInfo));
	}

	/**
	 * 修改游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhGameInfo zhGameInfo,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhGameInfo result = zhGameInfoService.selectZhGameInfoById(id);
		mmap.put("zhGameInfo", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhGameInfo.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:edit")
	@Log(title = "游戏", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhGameInfo zhGameInfo)
	{		
		return toAjax(zhGameInfoService.updateZhGameInfo(zhGameInfo));
	}
	
	/**
	 * 删除游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhGameInfo:remove")
	@Log(title = "游戏", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhGameInfo zhGameInfo,String ids)
	{		
		return toAjax(zhGameInfoService.deleteZhGameInfoByIds(ids));
	}
	
}
